AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")


function ENT:Initialize()
        self.Entity:SetModel("models/hunter/blocks/cube1x1x025.mdl")
        self.Entity:SetSkin(0)
        self.Entity:SetSolid(SOLID_VPHYSICS)
        local phys = self.Entity:GetPhysicsObject()
        if phys and phys:IsValid() then phys:Wake() end

end

function ENT:SpawnFunction( ply, tr ) 
   
         if ( !tr.Hit ) then return end 
          
         local SpawnPos = tr.HitPos + tr.HitNormal * 16 
          
         local ent = ents.Create( self.Classname ) 
         ent:SetPos( SpawnPos ) 
         ent:Spawn() 
         ent:Activate() 
          
         return ent 
          
 end 
 
local healsound = Sound("items/medshot4.wav")
local last_sound_time = 0
local last_heal_time = 0
local isTouching = false
function Givehealth( ent )
    if ( IsValid(ent) and ent:IsPlayer() ) then
        local health = ent:Health()
        local maxhealth = 100
        if (health < maxhealth) then
		if ( IsValid(ent) and ent:IsPlayer() ) then
            ent:SetHealth( health + 2 ) end
        else
            ent:SetHealth(maxhealth)
        end
            if (last_sound_time + 4 < CurTime() and ( health < maxhealth )) then
                ent:EmitSound(healsound)
                last_sound_time = CurTime()
            end
        end
end
 
function ENT:StartTouch( ent )
       if ( IsValid(ent) and ent:IsPlayer() ) then
            isTouching = true
        end
end

function ENT:Touch( ent )
    if ( isTouching ) then
        if last_heal_time + 1 > CurTime() then return end
            last_heal_time = CurTime()
            Givehealth(ent)
        end
    end

function ENT:EndTouch( ent )
        if ( IsValid(ent) and ent:IsPlayer() ) then
            isTouching = false
        end
end
 
function ENT:Think() 
end
